# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: api\classes\__init__.py
__author__ = "sanyi"
from api import undefined


def process_value(value):
    if isinstance(value, BaseResource):
        return value.to_dict()
    elif isinstance(value, dict):
        result = dict()
        for k, v in value.items():
            if v == undefined:
                continue
            result[k] = process_value(v)

        return result
    elif isinstance(value, (list, tuple)):
        result = []
        for v in value:
            result.append(process_value(v))

        return result
    else:
        return value


class BaseResource:
    def to_dict(self):
        return {
            key: process_value(value)
            for key, value in self.__dict__.items()
            if value != undefined
        }

    @classmethod
    def from_dict(cls, data, ignore_null_values=False):
        if ignore_null_values:
            data["ignore_null_values"] = True
        return cls(**data)

    def __getattribute__(self, name):
        value = object.__getattribute__(self, name)
        if value == undefined:
            raise AttributeError(name)
        return value

    def get(self, name, default=None):
        v = self.__dict__.get(name, default)
        if v == undefined:
            return default
        else:
            return v

    def is_complete(self, ignore_keys_list=None, recursive=True):
        for property_name, property_value in self.__dict__.items():
            if ignore_keys_list:
                if property_name in ignore_keys_list:
                    continue
                if property_value == undefined:
                    return False
                if isinstance(property_value, BaseResource):
                    if recursive:
                        if not property_value.is_complete(ignore_keys_list, recursive):
                            return False
            elif isinstance(property_value, (list, tuple)):
                if recursive:
                    for item in property_value:
                        if isinstance(item, BaseResource):
                            if not item.is_complete(ignore_keys_list, recursive):
                                return False

        return True
